package com.mapforge.selection;

import java.awt.Point;

public class SelectionSquareSizeModifier extends AbstractSelectionModifier {

	@Override
	public void doModify(Point startPoint, Point currentPoint) {
		int w = Math.abs(startPoint.x - currentPoint.x);
		int h = Math.abs(startPoint.y - currentPoint.y);
		int size = Math.min(w, h) + 1;
		// left
		if (currentPoint.x < startPoint.x) {
			// upper left
			if (currentPoint.y < startPoint.y) {
				currentPoint.x = startPoint.x - size + 1;
				currentPoint.y = startPoint.y - size + 1;
				// startPoint.x = startPoint.x - size + 1;
				// startPoint.y = startPoint.y - size + 1;
			}
			// bottom left
			else {
				currentPoint.x = startPoint.x - size + 1;
				currentPoint.y = startPoint.y + size - 1;
				// startPoint.x = startPoint.x - size + 1;
			}
		}
		// right
		else {
			// upper right
			if (currentPoint.y < startPoint.y) {
				currentPoint.x = startPoint.x + size - 1;
				currentPoint.y = startPoint.y - size + 1;
				// startPoint.y = startPoint.y - size + 1;
			}
			// bottom right
			else {
				currentPoint.x = startPoint.x + size - 1;
				currentPoint.y = startPoint.y + size - 1;
				// r.setLocation(startPoint.x, startPoint.y);
			}
		}
		System.out.println("SquareModifier: " + startPoint);
		
	}

}
